<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="中套名称" prop="sleeveName">
      <el-input v-model="dataForm.sleeveName" placeholder="中套名称"></el-input>
    </el-form-item>
    <el-form-item label="中套型号" prop="sleeveNo">
      <el-input v-model="dataForm.sleeveNo" placeholder="中套型号"></el-input>
    </el-form-item>
    <el-form-item label="规格描述" prop="sleeveDesc">
      <el-input v-model="dataForm.sleeveDesc" placeholder="规格描述"></el-input>
    </el-form-item>
    <el-form-item label="中套类别" prop="sleeveType">
      <el-input v-model="dataForm.sleeveType" placeholder="中套类别"></el-input>
    </el-form-item>
    <el-form-item label="中套口径" prop="bottleOutDiameter">
      <el-input v-model="dataForm.bottleOutDiameter" placeholder="中套口径"></el-input>
    </el-form-item>
    <el-form-item label="中套颜色" prop="sleeveColor">
      <el-input v-model="dataForm.sleeveColor" placeholder="中套颜色"></el-input>
    </el-form-item>
    <el-form-item label="中套的材质" prop="sleeveMaterial">
      <el-input v-model="dataForm.sleeveMaterial" placeholder="中套的材质"></el-input>
    </el-form-item>
    <el-form-item label="等级，A级。B级" prop="relateLevel">
      <el-input v-model="dataForm.relateLevel" placeholder="等级，A级。B级"></el-input>
    </el-form-item>
    <el-form-item label="图片信息" prop="relateImageInfo">
      <el-input v-model="dataForm.relateImageInfo" placeholder="图片信息"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          sleeveName: '',
          sleeveNo: '',
          sleeveDesc: '',
          sleeveType: '',
          bottleOutDiameter: '',
          sleeveColor: '',
          sleeveMaterial: '',
          relateLevel: '',
          relateImageInfo: '',
          remark: '',
          createUser: '',
          createTime: '',
          updateUser: '',
          updateTime: '',
          parentId: ''
        },
        // dataRule: {
        //   sleeveName: [
        //     { required: true, message: '中套名称不能为空', trigger: 'blur' }
        //   ],
        //   sleeveNo: [
        //     { required: true, message: '中套型号不能为空', trigger: 'blur' }
        //   ],
        //   sleeveDesc: [
        //     { required: true, message: '规格描述不能为空', trigger: 'blur' }
        //   ],
        //   sleeveType: [
        //     { required: true, message: '中套类别不能为空', trigger: 'blur' }
        //   ],
        //   bottleOutDiameter: [
        //     { required: true, message: '中套口径不能为空', trigger: 'blur' }
        //   ],
        //   sleeveColor: [
        //     { required: true, message: '中套颜色不能为空', trigger: 'blur' }
        //   ],
        //   sleeveMaterial: [
        //     { required: true, message: '中套的材质不能为空', trigger: 'blur' }
        //   ],
        //   relateLevel: [
        //     { required: true, message: '等级，A级。B级不能为空', trigger: 'blur' }
        //   ],
        //   relateImageInfo: [
        //     { required: true, message: '图片信息不能为空', trigger: 'blur' }
        //   ],
        //   remark: [
        //     { required: true, message: '备注不能为空', trigger: 'blur' }
        //   ],
        //   createUser: [
        //     { required: true, message: '创建者不能为空', trigger: 'blur' }
        //   ],
        //   createTime: [
        //     { required: true, message: '创建时间不能为空', trigger: 'blur' }
        //   ],
        //   updateUser: [
        //     { required: true, message: '更新者不能为空', trigger: 'blur' }
        //   ],
        //   updateTime: [
        //     { required: true, message: '更新时间不能为空', trigger: 'blur' }
        //   ],
        //   parentId: [
        //     { required: true, message: '父级不能为空', trigger: 'blur' }
        //   ]
        // }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatecentercoverinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.sleeveName = data.relateCenterCoverInfo.sleeveName
                this.dataForm.sleeveNo = data.relateCenterCoverInfo.sleeveNo
                this.dataForm.sleeveDesc = data.relateCenterCoverInfo.sleeveDesc
                this.dataForm.sleeveType = data.relateCenterCoverInfo.sleeveType
                this.dataForm.bottleOutDiameter = data.relateCenterCoverInfo.bottleOutDiameter
                this.dataForm.sleeveColor = data.relateCenterCoverInfo.sleeveColor
                this.dataForm.sleeveMaterial = data.relateCenterCoverInfo.sleeveMaterial
                this.dataForm.relateLevel = data.relateCenterCoverInfo.relateLevel
                this.dataForm.relateImageInfo = data.relateCenterCoverInfo.relateImageInfo
                this.dataForm.remark = data.relateCenterCoverInfo.remark
                this.dataForm.createUser = data.relateCenterCoverInfo.createUser
                this.dataForm.createTime = data.relateCenterCoverInfo.createTime
                this.dataForm.updateUser = data.relateCenterCoverInfo.updateUser
                this.dataForm.updateTime = data.relateCenterCoverInfo.updateTime
                this.dataForm.parentId = data.relateCenterCoverInfo.parentId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatecentercoverinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'sleeveName': this.dataForm.sleeveName,
                'sleeveNo': this.dataForm.sleeveNo,
                'sleeveDesc': this.dataForm.sleeveDesc,
                'sleeveType': this.dataForm.sleeveType,
                'bottleOutDiameter': this.dataForm.bottleOutDiameter,
                'sleeveColor': this.dataForm.sleeveColor,
                'sleeveMaterial': this.dataForm.sleeveMaterial,
                'relateLevel': this.dataForm.relateLevel,
                'relateImageInfo': this.dataForm.relateImageInfo,
                'remark': this.dataForm.remark,
                'createUser': this.dataForm.createUser,
                'createTime': this.dataForm.createTime,
                'updateUser': this.dataForm.updateUser,
                'updateTime': this.dataForm.updateTime,
                'parentId': this.dataForm.parentId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
